<!DOCTYPE html>
<html>
<head>
    <link rel='stylesheet' href='/stylesheets/users.css'/>
    <script src="/javascripts/jquery.js" charset="utf-8"></script>
    <script type="application/javascript" charset="utf-8">
        $(document).ready(function () {
            $('#exit').click(function (e) {
                window.location.href = 'http://' + window.location.host + '/invite/loginout';
            });
            $('#query').click(function (e) {
                var params = $('#condition').serialize();
                $.post(window.location.protocol+"//"+window.location.host+window.location.pathname + '?' + params, function (data) {
                    console.log(data);
                    if (data.code = 1) {
                        var listdom = '<tr>' +
                                '<td>申请时间</td>' +
                                '<td>姓名</td>' +
                                '<td>手机</td>' +
                                '<td>邮箱</td>' +
                                '<td>单位名称</td>' +
                                '<td>申请说明</td>' +
                                '<td>操作</td>' +
                                '</tr>';
                        var operation = '';
                        data.success.data.forEach(function (it) {
                            var td = new Date(it.date);

                            if (it.state == 0) {
                                operation = '<td ><form method="post" action="/invite/users/update?id=' + it._id + '&state=1"><button>通过</button></form><form method="post" action="/invite/users/update?id=' + it._id + '&state=-1"><button>拒绝</button></form></td>';
                            } else if (it.state == 1) {
                                operation = '<td ></td>';
                            } else if (it.state == -1) {
                                operation = '<td ><form method="post" action="/invite/users/update?id=' + it._id + '&state=1"><button>通过</button></form></td>';
                            }
                            listdom += '<tr>' +
                                    '<td>' + td.getFullYear() + '年' + (td.getMonth() + 1) + '月' + td.getDate() + '日' + td.getHours() + "时" + td.getMinutes() + "分" + '</td>' +
                                    '<td>' + it.name + '</td>' +
                                    '<td>' + it.phone + '</td>' +
                                    '<td>' + it.email + '</td>' +
                                    '<td>' + it.company + '</td>' +
                                    '<td>' + it.captcha + '</td>' +
                                    operation
                            '</tr>';
                        })
                    }
                    $("#list").empty();
                    $("#list").html(listdom);
                });
            });
        });
    </script>
</head>
<body>
<!--<div class="top">top</div>-->
<!--<div class="main">-->
<!--<div class="left"><ul><li>内测申请</li><li>账号生成</li></ul></div>-->
<div class="content">
    <form id="condition">
        <div style="text-align: center">

            姓名 <input type="text" name="name"/>
            电话 <input type="number" name="phone"/>
            邮箱 <input type="email" name="email"/>
            申请时间 <input type="date" name="dstart"/>-<input type="date" name="dend"/>
            状态<select name="state">
                <option value="">全部</option>
                <option value=0>待审批</option>
                <option value=1>审批通过</option>
                <option value=-1>审批拒绝</option>
            </select>
        </div>
    </form>
    <div style="margin-top:20px;margin-bottom:20px; text-align: center">
        <button id="query">查询</button>
        <button id="exit">退出</button>
    </div>
    <table id='list' border="1" cellpadding="0" cellspacing="0">
        <tr>
            <td>申请时间</td>
            <td>姓名</td>
            <td>手机</td>
            <td>邮箱</td>
            <td>单位名称</td>
            <td>内测案例描述</td>
            <td>操作</td>
        </tr>
        <% d.forEach(function(u){ %>
        <% var td = new Date(u.date) %>
        <tr>
            <td><%= td.getFullYear() + '年' + (td.getMonth() + 1) + '月' + td.getDate() + '日' + td.getHours() + "时" + td.getMinutes() + "分" %></td>
            <td><%= u.name %></td>
            <td><%= u.phone %></td>
            <td><%= u.email %></td>
            <td><%= u.company %></td>
            <td><%= u.captcha %></td>
            <% if (u.state == 0){ %>
            <td>
                <form method="post" action="/invite/users/update?id=<%= u._id %>&state=1">
                    <button>通过</button>
                </form>
                <form method="post" action="/invite/users/update?id=<%= u._id %>&state=-1">
                    <button>拒绝</button>
                </form>
            </td>
            <% } else if (u.state == 1){ %>
            <td></td>
            <% } else if (u.state == -1){ %>
            <td>
                <form method="post" action="/invite/users/update?id=<%= u._id %>&state=1">
                    <button>通过</button>
                </form>
            </td>
            <% } %>
        </tr>
        <% }) %>
    </table>
</div>
</body>
</html>
